package com.base.pig.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.base.pig.entity.CameraInfo;
import com.base.pig.entity.PumpGateStation;
import com.base.pig.service.CameraInfoService;
import com.base.pig.service.PumpGateStationService;

import com.base.pig.util.R;
import com.base.pig.vo.PumpVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjh
 * @since 2023-07-18
 */
@RestController
@Api(tags = "泵闸站接口")
@RequestMapping("/pump-gate-station")
public class PumpGateStationController {

    @Autowired
    public PumpGateStationService pumpGateStationService;

    @Autowired
    public CameraInfoService cameraInfoService;

    @ApiOperation(value = "泵闸站列表查询")
    @PostMapping("/list")
    public R list(){
        List<PumpGateStation> pumpGateStationList = pumpGateStationService.list(Wrappers.<PumpGateStation>query().lambda().orderByAsc(PumpGateStation::getId));
        List<PumpVo> list = new ArrayList<PumpVo>();
        pumpGateStationList.forEach(pumpGateStation -> {
            PumpVo vo = new PumpVo();
            BeanUtils.copyProperties(pumpGateStation,vo);
            String num = pumpGateStation.getNum();
            List<CameraInfo> cameraList = cameraInfoService.list(Wrappers.<CameraInfo>query().lambda().eq(CameraInfo::getSncode,num));
            vo.setCameralist(cameraList);
            list.add(vo);
        });
        return R.ok(list,"查询成功");
    }




}
